package com.crm.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.crm.utils.UserThreadLocal;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDateTime;


/**
 * @author Xanny
 */
@Configuration
@RequiredArgsConstructor
public class MybatisPlusAutoFill implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        Long userId = UserThreadLocal.getUserId();
//        this.setFieldValByName("createBy", userId.toString(), metaObject);
        this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
    }
}
